<?php
include_once '../../__global.php';

class aj_getAttitudeCountByRid extends ml_controller
{
    private $_rid;
    private $_aid;
    
    function initParam() {
        
        $this->_rid = $this->input('rid','G',0);
        $this->_aid = $this->__visitor['uid'];
    }
    
    function checkParam() {
        
        $this->check_referer();
        if (!ml_tool_resid::is_resid($this->_rid)) {
            $this->api_output(ML_RCODE_PARAM);
        }
        
    }
    
    function main() {
            
        $oRedisC = new ml_model_rdsCount();
        $re = $oRedisC->getAttitudeCount(array($this->_rid));
        $Ac = $oRedisC->get_data();
        $count = intval($Ac[$this->_rid]);
        
        if (!$re) {
            $likeme = new ml_model_dbLikeMe();
            $oid = ml_tool_resid::resid2uid($this->_rid);
            $re = $likeme->countContentAttUser($oid, $this->_rid, $count);
            if (!$re) {
                $this->api_output(ML_RCODE_BUSY);
            }
        }
        
        $islike = false;
        if (!empty($this->_aid)) {
            $ilike = new ml_model_dbILike();
            $rs = $ilike->isIAttByRid($this->_aid, $this->_rid, $isExist);
            
            if ($isExist) {
                $islike = true;
            }
        }
    
        
        $data['islike'] = $islike;
        $data['count'] = $count;
        $data['rid'] = $this->_rid;
        $this->api_output(ML_RCODE_SUCC, $data);
        
        
    }
    
    
}

new aj_getAttitudeCountByRid();